< previous page page_210 next page >

Page 210
Private Declare Function RasEntryToMemBuffer Lib "kernel32" Alias _
"RtlMoveMemory" (dest As Byte, source As RASENTRYNAME, _
ByVal count As Long) As Long
Private Declare Function RasEntryFromMemBuffer Lib "kernel32" _
Alias "RtlMoveMemory" (dest As RASENTRYNAME, source As Byte, _
ByVal count As Long) As Long

Dim TransferBuffer() As Byte

For CurrentEntry = 0 To RasEntryCount - 1
         RasEntryBuffer(CurrentEntry).dwSize = RasEntrySize
         Call RasEntryToMemBuffer(TransferBuffer( _
         CurrentEntry * RasEntrySize), RasEntryBuffer(CurrentEntry), _
         RasEntrySize)
Next CurrentEntry
Why do you need to create a separate function to do the copy instead of just using RtlMoveMemory directly? The truth is, you don't. This approach just adds some clarity and safety to the process. You could just as well have used RtlMoveMemory directly with the parameters declared As Any. But you could not have declared the parameters ByVal As Long and used the VarPtr operator. Why? Because the VarPtr operator would return the address of the structure in memorythe Visual Basic structure with its internal Unicode string.
0210-01.gif
Figure S18-2:
Loading structures into a byte array
When the RasEntryToMemBuffer function is called, the specified RasEntryBuffer entry is converted into ANSI, and a pointer to that temporary structure is passed to the RtlMoveMemory function, which then copies the data into the specified location in the TransferBuffer byte array. After the TransferBuffer byte array is completely loaded, the RasEnumEntries function can be called with the correct data, as shown in Figure S18-2.
After the RasEnumEntries loads the TransferBuffer array with the phone book entries, the process can be reversed. The RasEntryFromMemBuffer function is

 
< previous page page_210 next page >